VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmARSIList 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Sales Invoice Details"
   ClientHeight    =   5325
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   8565
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmARSIList.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   5325
   ScaleWidth      =   8565
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame Frame4 
      Caption         =   "Product Listing"
      Height          =   2505
      Left            =   60
      TabIndex        =   9
      Top             =   2325
      Width           =   8430
      Begin MSComctlLib.ListView lvwList 
         Height          =   2130
         Left            =   120
         TabIndex        =   1
         Top             =   255
         Width           =   8190
         _ExtentX        =   14446
         _ExtentY        =   3757
         View            =   3
         Sorted          =   -1  'True
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         FullRowSelect   =   -1  'True
         GridLines       =   -1  'True
         HotTracking     =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   0
         NumItems        =   10
         BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            Text            =   "Product ID"
            Object.Width           =   2646
         EndProperty
         BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            SubItemIndex    =   1
            Text            =   "Description"
            Object.Width           =   3528
         EndProperty
         BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            SubItemIndex    =   2
            Text            =   "Warehouse"
            Object.Width           =   1764
         EndProperty
         BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            SubItemIndex    =   3
            Text            =   "Unit"
            Object.Width           =   1102
         EndProperty
         BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            SubItemIndex    =   4
            Text            =   "Quantity"
            Object.Width           =   1587
         EndProperty
         BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            SubItemIndex    =   5
            Text            =   "Price"
            Object.Width           =   1587
         EndProperty
         BeginProperty ColumnHeader(7) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            SubItemIndex    =   6
            Text            =   "Amount"
            Object.Width           =   1799
         EndProperty
         BeginProperty ColumnHeader(8) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            SubItemIndex    =   7
            Text            =   "Reference Identity"
            Object.Width           =   0
         EndProperty
         BeginProperty ColumnHeader(9) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            SubItemIndex    =   8
            Text            =   "Cost"
            Object.Width           =   0
         EndProperty
         BeginProperty ColumnHeader(10) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            SubItemIndex    =   9
            Text            =   "Factor"
            Object.Width           =   0
         EndProperty
      End
   End
   Begin VB.Frame Frame1 
      Height          =   2205
      Left            =   60
      TabIndex        =   4
      Top             =   60
      Width           =   8430
      Begin MSComctlLib.ListView lvwRef 
         Height          =   1845
         Left            =   105
         TabIndex        =   0
         Top             =   225
         Width           =   1635
         _ExtentX        =   2884
         _ExtentY        =   3254
         View            =   3
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         FullRowSelect   =   -1  'True
         GridLines       =   -1  'True
         HotTracking     =   -1  'True
         _Version        =   393217
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   0
         NumItems        =   1
         BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
            Text            =   "Reference No."
            Object.Width           =   2646
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtCode 
         Height          =   285
         Left            =   2010
         TabIndex        =   5
         Top             =   240
         Width           =   2265
         _ExtentX        =   3784
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         AllCaps         =   -1  'True
         Mandatory       =   -1  'True
         Locked          =   -1  'True
         Label           =   "Customer"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1205
      End
      Begin ITGControls.ITGDateBox dtbDate 
         Height          =   285
         Left            =   3045
         TabIndex        =   6
         Tag             =   "Order Date"
         Top             =   600
         Width           =   1275
         _ExtentX        =   2249
         _ExtentY        =   503
         Enabled         =   0   'False
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   ""
         SendKeysTab     =   -1  'True
         Mandatory       =   -1  'True
         DatePicker      =   0   'False
      End
      Begin ITGControls.ITGLabel ITGLabel4 
         Height          =   285
         Left            =   2085
         TabIndex        =   7
         Top             =   600
         Width           =   915
         _ExtentX        =   1614
         _ExtentY        =   503
         Caption         =   "DR Date"
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtName 
         Height          =   285
         Left            =   4365
         TabIndex        =   8
         Top             =   240
         Width           =   3930
         _ExtentX        =   6826
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Locked          =   -1  'True
         Label           =   "ITGtext"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   0
         TextBoxWidth    =   3870
      End
   End
   Begin ITGControls.ITGCommandButton cmdCancel 
      Height          =   345
      Left            =   7290
      TabIndex        =   3
      Top             =   4920
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&Cancel"
   End
   Begin ITGControls.ITGCommandButton cmdOK 
      Height          =   345
      Left            =   6030
      TabIndex        =   2
      Top             =   4920
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&OK"
   End
   Begin ITGControls.ITGCommandButton cmdCAll 
      Height          =   345
      Left            =   60
      TabIndex        =   10
      Top             =   4920
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Check All"
   End
   Begin ITGControls.ITGCommandButton cmdUCAll 
      Height          =   345
      Left            =   1320
      TabIndex        =   11
      Top             =   4920
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Uncheck All"
   End
End
Attribute VB_Name = "frmARSIList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.09.23

Option Explicit

Enum eSIType
    DR
'    DR_SampleDemo
    INVOICE
    InvoiceJobber
    InvoiceExhibit
    Invoice_CMAdjustment
    Invoice_Consignment
    Supplier_
    WALKIN
End Enum

Public mType As eSIType
Public mRefPK As String
Public mItem As String
Public mDesc As String
Public mRefID As Long


Private connList As New ADODB.Connection

Private Sub cmdCAll_Click()
    If lvwList.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwList.ListItems.Count
        lvwList.ListItems(i).Checked = True
    Next i
End Sub

Private Sub cmdCancel_Click()
    Unload Me
    Set frmARSIList = Nothing
End Sub

Private Sub cmdOK_Click()
    If mType <> Invoice_CMAdjustment Then FrmName.AddDetailsFromList
    Unload Me
End Sub

Private Sub cmdUCAll_Click()
    If lvwList.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwList.ListItems.Count
        lvwList.ListItems(i).Checked = False
    Next i
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        Unload Me
        Set frmARSIList = Nothing
    End If
End Sub

Private Sub Form_Load()
    Select Case mType
        Case DR
            Reference "cDRNo", "DR", "cDelCode = '" & RepName & "' AND ISNULL(cInvNo, '') = '' AND cType IN ('Issues') AND lCancelled = 0"
            Caption = "Sales Invoice Detail List [Reference: Delivery Receipt]"
        Case DR_SampleDemo
            Reference "cDRNo", "V_DRForSI", "cDelCode = '" & RepName & "'"
            Caption = "Sales Invoice Detail List [Reference: Delivery Receipt (Sample/Demo)]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case INVOICE
            Reference "cSONo", "V_SOForDR", "cCode = '" & RepName & "' AND cType in ('Regular')"
            Caption = "Sales Invoice Detail List [Reference: Sales Order]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case WALKIN
            Reference "cSONo", "V_SOForDR", "cCode = '" & RepName & "' AND cType in ('Walk-In')"
            Caption = "Sales Invoice Detail List [Reference: Sales Order]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case Supplier_
            Reference "cSONo", "V_SOForDR", "cCode = '" & RepName & "' AND cType in ('CORPORATE')"
            Caption = "Sales Invoice Detail List [Reference: Sales Order - Supplier]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case InvoiceJobber
            Reference "cSONo", "V_SOForDR", "cCode = '" & RepName & "' AND cType in ('Jobber')"
            Caption = "Sales Invoice Detail List [Reference: Sales Order]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case InvoiceExhibit
            Reference "cSONo", "V_SOForDR", "cCode = '" & RepName & "' AND cType in ('Exhibit')"
            Caption = "Sales Invoice Detail List [Reference: Sales Order]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case Invoice_Consignment
            Reference "cSONo", "V_SOForDR", "cCode = '" & RepName & "' AND cType = 'For Sales-Con'"
            Caption = "Sales Invoice Consignment Detail List [Reference: Sales Order]"
            lvwList.Checkboxes = True
            cmdCAll.Visible = True
            cmdUCAll.Visible = True
        Case Invoice_CMAdjustment
            Set itmX = lvwRef.ListItems.Add(, , RepName)
            Caption = "Sales Invoice Product List"
    End Select
    If lvwRef.ListItems.Count <> 0 Then lvwRef_ItemClick lvwRef.ListItems(lvwRef.SelectedItem.Index)
End Sub

'Reference list
Sub Reference(RefField As String, RefTable As String, Optional Condition As String)
    
    If Trim(Condition) <> "" Then
        Condition = " AND " & Condition
    End If
    
    'Select reference numbers
    sSQL = "SELECT DISTINCT " & Trim(RefField) & " AS cRefNo FROM " & Trim(RefTable) & " WHERE cCompanyID = '" & COID & "'" & Condition
    OpenNewConnection connList
    Set rs = New Recordset
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    lvwRef.ListItems.Clear
    Do Until rs.EOF
        Set itmX = lvwRef.ListItems.Add(, , Trim(rs!cRefNo))
    rs.MoveNext
    Loop
    Set rs = Nothing

End Sub

'Sets the SQL Query for SI item details
Sub ListQuery(RefPK As String)

    Select Case mType
        Case DR
            sSQL = "SELECT cDelCode AS RefCode, (SELECT cName FROM CLIENT_CUSTOMER WHERE cCode = A.cDelCode AND cCompanyID = '" & COID & "') AS RefName, " & _
                    "dDate AS RefDate FROM DR A WHERE cDRNo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListHeader
            sSQL = "SELECT cItemNo, cDesc, cWH, cUnit, nQty, nPrice, nAmount, nIdentity, nCost, nFactor FROM DR_T " & _
                    "WHERE cDRNo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListDetail
        Case DR_SampleDemo
            sSQL = "SELECT cDelCode AS RefCode, (SELECT cName FROM CLIENT_CUSTOMER WHERE cCode = A.cDelCode AND cCompanyID = '" & COID & "') AS RefName, " & _
                    "dDate AS RefDate FROM DR A WHERE cDRNo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListHeader
            sSQL = "SELECT DR_T.cItemNo, cDesc, cWH, cUnit, (nQty - ISNULL(nInvoiced, 0)) AS nQty, nPrice, ((nQty - ISNULL(nInvoiced, 0)) * nPrice) AS nAmount, nIdentity, ISNULL(nCost,0) AS nCost, nFactor FROM DR_T " & _
                    "LEFT OUTER JOIN V_InvoicedDRItem A ON DR_T.nIdentity = A.nRefIdentity AND DR_T.cItemNo = A.cItemNo " & _
                    "WHERE DR_T.cDRNo = '" & Trim(RefPK) & "' AND DR_T.cCompanyID = '" & COID & "'" & _
                    "AND (nQty - ISNULL(nInvoiced, 0)) > 0"
            ListDetail
        Case INVOICE, InvoiceExhibit, InvoiceJobber, Supplier_, WALKIN
            sSQL = "SELECT cCode AS RefCode, (SELECT cName FROM CLIENT_CUSTOMER WHERE cCode = A.cCode AND cCompanyID = '" & COID & "') AS RefName, " & _
                    "dDate AS RefDate FROM SO A WHERE cSONo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListHeader
            sSQL = "SELECT SO_T.cItemNo, cDesc, cWH, cUnit, (nQty - ISNULL(nDelivered, 0)) AS nQty, nNetPrice AS nPrice, ((nQty - ISNULL(nDelivered, 0)) * nNetPrice) AS nAmount, nIdentity, 0 AS nCost, nFactor FROM SO_T " & _
                    "LEFT OUTER JOIN V_DeliveredSOItem A ON SO_T.nIdentity = A.nRefIdentity AND SO_T.cItemNo = A.cItemNo " & _
                    "WHERE SO_T.cSONo = '" & Trim(RefPK) & "' AND SO_T.cCompanyID = '" & COID & "' AND lDRReady = 1 " & _
                    "AND (nQty - ISNULL(nDelivered, 0)) > 0"
            ListDetail
        Case Invoice_Consignment
            sSQL = "SELECT cCode AS RefCode, (SELECT cName FROM CLIENT_CUSTOMER WHERE cCode = A.cCode AND cCompanyID = '" & COID & "') AS RefName, " & _
                    "dDate AS RefDate FROM SO A WHERE cSONo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListHeader
            sSQL = "SELECT SO_T.cItemNo, cDesc, cWH, cUnit, (nQty - ISNULL(nDelivered, 0)) AS nQty, nNetPrice AS nPrice, ((nQty - ISNULL(nDelivered, 0)) * nNetPrice) AS nAmount, nIdentity, 0 AS nCost, nFactor FROM SO_T " & _
                    "LEFT OUTER JOIN V_DeliveredSOItem A ON SO_T.nIdentity = A.nRefIdentity AND SO_T.cItemNo = A.cItemNo " & _
                    "WHERE SO_T.cSONo = '" & Trim(RefPK) & "' AND SO_T.cCompanyID = '" & COID & "' AND lDRReady = 1 " & _
                    "AND (nQty - ISNULL(nDelivered, 0)) > 0"
            ListDetail
        Case Invoice_CMAdjustment
            sSQL = "SELECT cCode AS RefCode, (SELECT cName FROM CLIENT_CUSTOMER WHERE cCode = A.cCode AND cCompanyID = '" & COID & "') AS RefName, " & _
                    "dDate AS RefDate FROM SALES A WHERE cInvNo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListHeader
            sSQL = "SELECT cItemNo, cDesc, cWH, cUnit, nQty, nPrice, nAmount, nIdentity, ISNULL(nCost,0) AS nCost, nFactor FROM SALES_T " & _
                    "WHERE cInvNo = '" & Trim(RefPK) & "' AND cCompanyID = '" & COID & "'"
            ListDetail
    End Select

End Sub

'Header details
Sub ListHeader()
    OpenNewConnection connList
    Set rs = New Recordset
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    If rs.RecordCount <> 0 Then
        txtCode = rs!RefCode & ""
        txtName = rs!refname & ""
        dtbDate.Text = Format(rs!RefDate, "MM/dd/yyyy") & ""
    End If
    Set rs = Nothing
End Sub

'Item details
Sub ListDetail()
    Set rs = New Recordset
    DoEvents
    
    OpenNewConnection connList
    rs.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly
    lvwList.ListItems.Clear
    lvwList.Visible = False
    Do Until rs.EOF
        Set itmX = lvwList.ListItems.Add(, , Trim(rs!cItemNo) & "")
        itmX.SubItems(1) = Trim(rs!cDesc) & ""
        itmX.SubItems(2) = Trim(rs!cWH) & ""
        itmX.SubItems(3) = Trim(rs!cUnit) & ""
        itmX.SubItems(4) = Format(rs!nQty, "###,##0.#0") & ""
        itmX.SubItems(5) = Format(rs!nPrice, "###,##0.#000") & ""
        itmX.SubItems(6) = Format(rs!nAmount, "###,##0.#0") & ""
        itmX.SubItems(7) = rs!nIdentity & ""
        itmX.SubItems(8) = rs!nCost & ""
        itmX.SubItems(9) = rs!nFactor & ""
        rs.MoveNext
    Loop
    lvwList.Visible = True
    Set rs = Nothing
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set connList = Nothing
End Sub

Private Sub lvwList_GotFocus()
    If lvwList.ListItems.Count <> 0 Then lvwList_ItemClick lvwList.ListItems(lvwList.SelectedItem.Index)
End Sub

Private Sub lvwList_ItemClick(ByVal Item As MSComctlLib.ListItem)
    If lvwList.ListItems.Count = 0 Then Exit Sub
    mItem = Trim(lvwList.SelectedItem)
    mDesc = Trim(lvwList.SelectedItem.SubItems(1))
    mRefID = Trim(lvwList.SelectedItem.SubItems(7))
End Sub

Private Sub lvwList_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If lvwList.SelectedItem.Checked = True Then
            lvwList.SelectedItem.Checked = False
        Else
            lvwList.SelectedItem.Checked = True
        End If
    End If
End Sub

Private Sub lvwRef_ItemClick(ByVal Item As MSComctlLib.ListItem)
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    mRefPK = Trim(lvwRef.SelectedItem)
    ListQuery (Trim(lvwRef.SelectedItem))
End Sub

Private Sub lvwRef_KeyPress(KeyAscii As Integer)
    If lvwRef.ListItems.Count = 0 Then Exit Sub
    If KeyAscii = 13 Then lvwRef_ItemClick lvwRef.ListItems(lvwRef.SelectedItem.Index)
End Sub


